package cn.iocoder.yudao.module.infra.repository.mybatis.dao.job;

import cn.iocoder.yudao.common.pojo.PageResult;
import cn.iocoder.yudao.core.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.core.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.infra.repository.mybatis.domain.job.JobLog;
import cn.iocoder.yudao.module.infra.vo.job.log.JobLogExportReqVO;
import cn.iocoder.yudao.module.infra.vo.job.log.JobLogPageReqVO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 任务日志 Mapper
 */
@Mapper
public interface JobLogMapper extends BaseMapperX<JobLog> {

    default PageResult<JobLog> selectPage(JobLogPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<JobLog>()
                .eqIfPresent(JobLog::getJobId, reqVO.getJobId())
                .likeIfPresent(JobLog::getHandlerName, reqVO.getHandlerName())
                .geIfPresent(JobLog::getBeginTime, reqVO.getBeginTime())
                .leIfPresent(JobLog::getEndTime, reqVO.getEndTime())
                .eqIfPresent(JobLog::getStatus, reqVO.getStatus())
                .orderByDesc(JobLog::getId) // ID 倒序
        );
    }

    default List<JobLog> selectList(JobLogExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<JobLog>()
                .eqIfPresent(JobLog::getJobId, reqVO.getJobId())
                .likeIfPresent(JobLog::getHandlerName, reqVO.getHandlerName())
                .geIfPresent(JobLog::getBeginTime, reqVO.getBeginTime())
                .leIfPresent(JobLog::getEndTime, reqVO.getEndTime())
                .eqIfPresent(JobLog::getStatus, reqVO.getStatus())
                .orderByDesc(JobLog::getId) // ID 倒序
        );
    }

}
